<?php

namespace app\api\controller\v1;

use addons\litestore\model\Litestoregoodsspec;
use addons\litestore\model\Litestoreorder;
use addons\litestore\model\Wxlitestoregoods;
use app\admin\model\Factoryapply;
use app\admin\model\Factoryorder;
use app\admin\model\litestore\Litestoregoods;
use app\admin\model\litestore\Litestorenews;
use app\admin\model\Pingoods;
use app\admin\model\Pinjoin;
use app\admin\model\Pinprofit;
use app\admin\model\Pinuser;
use app\admin\model\unilive\Room;
use app\admin\model\Useraddress;
use app\admin\model\Userrelation;
use app\admin\model\Userweixin;
use app\api\service\LepayService;
use app\api\service\Orderservice;
use app\common\controller\Api;

/**
 */
class Factory extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];

    public function check(){
        $user = $this->auth->getUser();
        $uid = $user['id'];
        $factoryModel = new Factoryapply();
        $factory = $factoryModel->where('uid',$uid)->find();
        $factoryModel = new Factoryorder();
        if($factory){
            $order = $factoryModel->where('uid',$uid)->where('orderStatus','payed')->find();
            if(!$order){
                $this->error('还没交押金',"",-2);
            }else{
                $this->error('已提交过，请勿重复提交');
            }
        }else{
            $this->success('');
        }
    }

    public function apply(){

        $shopname = $this->request->param('shopname');
        $img1 = $this->request->param('img1');
        $img2 = $this->request->param('img2');
        $img3 = $this->request->param('img3');
        $mobile = $this->request->param('mobile');
        $name = $this->request->param('name');
        $fa = $this->request->param('fa');
        $user = $this->auth->getUser();
        $uid = $user['id'];


        if(!$shopname || !$img1 || !$img2 || !$img3 || !$mobile || !$name){
            $this->error("填写数据错误");
        }
        if($user['group_id'] <= 1){

            $this->error("","",-2);
        }
        $factoryModel = new Factoryapply();
        $id = $factoryModel->insertGetId(['shopname'=>$shopname,'uid'=>$uid,
            'username'=>$name,'mobile'=>$mobile,'createtime'=>time(),
            'license'=>$img1,'pimg1'=>$img2,'pimg2'=>$img3,'fa'=>$fa]);
        if($id >0){
            $this->success('成功');
        }else{
            $this->error('入驻失败，请联系客服');
        }


    }


}
